package com.njlime.cms.service.sys;

import com.njlime.cms.entities.LiveConfig;
import com.njlime.cms.repository.sys.LiveConfigDao;
import com.njlime.core.helper.GlobalValue;
import com.njlime.sys.entities.UnitWxConfig;
import com.njlime.sys.service.UserConfigService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.Date;

/**
 * Created by Dean on 2017/10/13.
 */
@Service
@Transactional(readOnly = true)
public class LiveConfigService {
    @Resource
    private LiveConfigDao liveConfigDao;

    @Resource
    private UserConfigService userConfigService;
    /**
     * 编辑直播设置
     * @param liveConfig
     * @return
     */
    @Transactional(readOnly = false)
    public void setConfig(LiveConfig liveConfig){
        liveConfigDao.delCurConfig(liveConfig.getUnit_id());
        liveConfig.setId(null);
        liveConfig.setCreate_time(new Date());
        liveConfig.setIs_del(GlobalValue.NO);
        liveConfigDao.save(liveConfig);
    }

    /**
     * 获取当前有效的直播设置
     * @param unit_id
     * @return
     */
    public LiveConfig getConfig(Integer unit_id){
        return liveConfigDao.getCurConfig(unit_id);
    }

    @Transactional(readOnly = false)
    public void edit(LiveConfig info, Integer userConfigId) {

            liveConfigDao.edit(info);

        userConfigService.updateStatus(userConfigId);
    }
}
